﻿using System;
using System.Diagnostics;

namespace Project2_SumOfEvenFibonacciNumbersUnder4Million {
    class Program {
        static void Main(string[] args) {


            Console.WriteLine("Project Euler Problem 2: Find the sum of all the even-valued terms in the Fibonacci sequence which do not exceed four million");
            Stopwatch timer = new Stopwatch();

            const int LIMIT = 4000000;

            timer.Start();

            int term1 = 1;
            int term2 = 2;
            int sum = term2;

            while (term1 + term2 < LIMIT) {
                int nextTerm = term1 + term2;

                if (nextTerm % 2 == 0) {
                    sum += nextTerm;
                }

                term1 = term2;
                term2 = nextTerm;
            }

            timer.Stop();
            Console.WriteLine("\nAnswer: {0}\nin {1}ms ({2} ticks)", sum, timer.ElapsedMilliseconds, timer.ElapsedTicks);
            Console.WriteLine("\nPress RETURN to exit...");
            Console.ReadLine();
        }
    }
}
